﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using MyECommerceProject.Models;


namespace MyECommerceProject.Data.Configurations
{
    public class InventoryConfiguration : IEntityTypeConfiguration<Inventory>
    {
        public void Configure(EntityTypeBuilder<Inventory> builder)
        {
            builder.HasKey(i => i.InventoryId);
            builder.Property(i => i.ProductId).IsRequired();
            builder.Property(i => i.Sell).IsRequired();
            builder.Property(i => i.Count).IsRequired();
            builder.Property(i => i.OperationDate).IsRequired().HasDefaultValueSql("GETDATE()");

            // 配置外键关系
            builder.HasOne(i => i.Product)
                   .WithMany(p => p.Inventories)  // 指定 Product 实体的集合导航属性
                   .HasForeignKey(i => i.ProductId);
        }
    }
}
